TextWidth function

Syntax
TextWidth text [, fontname] [, size] [, style]

Description
Returns the width of a line of text (in pixels) using the specified fontname, size, and style number. If you omit any of the optional parameters, TextWidth uses default values of Geneva, 9-point, plain style in place of any missing parameters.

The style parameter is a number you can specify yourself or get from a button's .TextStyle property. Add style numbers together to combine styles.

0: Plain Text
1: Bold
2: Italic
4: Underline
8: Outline
16: Shadow
32: Condense
64: Extend

Examples
// Get the width of the text in Palatino 12-point bold, italic
Variable W
W = TextWidth "sample text to measure", "Palatino", 12, 3

// Get the width of the text in Geneva 9-point plain
W = TextWidth "sample text to measure"

// Set the button's width to the width of its text.
// Allow extra room for the button's border width, which can be
// anywhere from 3 to 17 pixels depending on the border style.
Variable Extra
Extra = 7           // left + right border widths
With Button
     .Border = 1
     .Width = Extra + TextWidth .Text, .TextFont, .TextSize, .TextStyle
End With 

Author Info
TextWidth, part of FitText Extension
Copyright © 1999 Jeff Jungblut. All rights reserved.

See Also
TruncText function (page 299), Button object (page 176)